<template>
  <div class="article-list">
    <h1>博客列表文章</h1>
    <el-row justify="center">
      <el-col :span="6">
        <el-card :body-style="{ padding: '0px' }" @click="startGuessGame(1)">
          <img src="@/assets/wukong.jpg" class="image">
          <div style="padding: 14px;">
            <span>猜字游戏</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button">操作按钮</el-button>
            </div>
          </div>
        </el-card>
        <transition name="fade">
          <div v-if="showInput && activeGameId === 1">
            <input v-model="userGuess" type="number" placeholder="请输入一个数字">
            <button @click="checkGuess">提交</button>
            <p v-if="resultMessage">{{ resultMessage }}</p>
          </div>
        </transition>
      </el-col>
      <el-col :span="6" :offset="3">
        <!-- 添加 @click 事件 -->
        <el-card :body-style="{ padding: '0px' }" @click="showWebFrontendTip">
          <img src="@/assets/book.jpg" class="image">
          <div style="padding: 14px;">
            <span>精品书籍</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button">操作按钮</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6" :offset="3">
        <el-card :body-style="{ padding: '0px' }" @click="openBilibiliSpace">
          <img src="@/assets/bilibili.jpg" class="image">
          <div style="padding: 14px;">
            <span>社交媒体</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button">操作按钮</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<style>
  .time {
    font-size: 13px;
    color: #999;
    /* 添加居中样式 */
    text-align: center; 
    display: block; /* 确保 time 元素作为块级元素，使居中生效 */
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }
</style>

<script>
export default {
  data() {
    const date = new Date();
    const formattedDate = `${date.toDateString()} ${date.toTimeString().split(' ')[0]}`;
    return {
      currentDate: formattedDate
    };
  },
  methods: {
    // 定义事件处理函数
    showWebFrontendTip() {
      alert('Web前端开发技术     武湖校区 2-3-8     1-12周');
    },
    openBilibiliSpace() {
      window.open('https://space.bilibili.com/605090250?spm_id_from=333.337.0.0', '_blank');
    }
  }
}
</script>

<script setup>
import { ref } from 'vue';


const showInput = ref(false);
const userGuess = ref('');
const resultMessage = ref('');
const activeGameId = ref(null);
const currentGameId = ref(1); // 猜字游戏的 id
const randomNumber = ref(Math.floor(Math.random() * 100) + 1); // 生成 1 到 100 的随机数

const startGuessGame = (id) => {
  if (id === currentGameId.value) {
    showInput.value = true;
    activeGameId.value = id;
    randomNumber.value = Math.floor(Math.random() * 100) + 1; // 重新生成随机数
    userGuess.value = '';
    resultMessage.value = '';
  }
};
//检查
const checkGuess = () => {
  const guess = parseInt(userGuess.value, 10);
  if (isNaN(guess)) {
    resultMessage.value = '请输入有效的数字。';
    return;
  }
  if (guess > randomNumber.value) {
    resultMessage.value = '太大了，请尝试小一点的数字。';
  } else if (guess < randomNumber.value) {
    resultMessage.value = '太小了，请尝试大一点的数字。';
  } else {
    alert('恭喜你，猜对了！');
    showInput.value = false;
  }
};
</script>
